package com.xinyue.exceltool;

import com.xinyue.dataconfig.ItemConfig;
import com.xinyue.exceltool.logic.ReadExcelService;
import com.xinyue.game.dataconfig.GameDataConfigContext;
import com.xinyue.game.dataconfig.GameDataConfigService;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;

import java.util.Collection;

@SpringBootApplication
public class GameExcelToolMain {

    public static void main(String[] args) {
        SpringApplication app = new SpringApplication(GameExcelToolMain.class);
        app.setWebApplicationType(WebApplicationType.NONE);
        ApplicationContext context = app.run(args);

        ReadExcelService readExcelService = context.getBean(ReadExcelService.class);
        readExcelService.printConfig();
        readExcelService.checkExcelFilePath();
        readExcelService.readExcel();
        //读取json配置到内存的测试
        // loadDataConfig(context);
    }

    private static void loadDataConfig(ApplicationContext context) {
        GameDataConfigContext gameDataConfigContext = context.getBean(GameDataConfigContext.class);
        String configDir = "config/server_data";
        String classPck = "com.xinyue.dataconfig";
        try {
            gameDataConfigContext.startReload(configDir, classPck);
            GameDataConfigService gameDataConfigService = context.getBean(GameDataConfigService.class);
            Collection<ItemConfig> allDataConfigList = gameDataConfigService.getAllDataConfigList(ItemConfig.class);
            allDataConfigList.forEach(c -> System.out.println(c.getId() + "," + c.isTest5()));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
